{extend name="base" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-header">
        <div class="layui-form toolbar">
            <div class="layui-form-item">
                <form action="{:request()->url()}" class="layui-form" method="get">
                <div class="layui-inline" style="padding-left: 0px;">
                    <a href="{:url('wechat/template/update')}" class="layui-btn layui-btn-warm ajax-action"><i class="fa fa-star"></i> 更新模板</a>
                </div>
                
                <div class="layui-inline" style="padding-left: 20px;">
                    <button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i> 搜索</button>
                </div>
                </form>
            </div>
        </div>
    </div>
    <table class="layui-table" id="tableTrack" lay-filter="tableTrack"></table>
    <!-- 表格状态列 -->
    <script type="text/html" id="demoEDStateBar1">
        {{# if(d.subscribe==0){ }}
        <button class="layui-btn layui-btn-xs layui-btn-primary">未关注</button>
        {{# }else if(d.subscribe==1){ }}
        <button class="layui-btn layui-btn-xs layui-btn-normal">已关注</button>
        {{# } }}
    </script>
    <!-- 表格状态列 -->
    <script type="text/html" id="task">
        {{# if(d.task_count == 0){ }}
        <a href="{:url('wechat/template/task')}?id={{d.id}}" class="layui-btn layui-btn-xs layui-btn-primary ajax-detail">暂无任务</a>
        {{# }else{ }}
        {if auth_url('wechat/template/task_send')}
        <a href="{:url('wechat/template/task_send')}?id={{d.id}}" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe609;</i>发送{{d.task_count}}条</a>
        {else}
        <a class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe609;</i>{{d.task_count}}条待发</a>
        {/if}
        {{# } }}
    </script>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        {if auth_url('wechat/template/task_add')}
        <a href="{:url('wechat/template/task_add')}?tid={{d.id}}" class="layui-btn layui-btn-sm ajax-iframe" data-width="800px" data-height="100%"><i class="layui-icon">&#xe61f;</i>新建发送任务</a>
        {/if}
        {if auth_url('wechat/template/edit')}
        <a href="{:url('wechat/template/edit')}?id={{d.id}}" class="layui-btn layui-btn-sm ajax-iframe" data-width="800px" data-height="100%"><i class="layui-icon">&#xe642;</i>编辑模板</a>
        {/if}
        {if auth_url('wechat/template/del')}
        <a href="{:url('wechat/template/del')}?id={{d.id}}" class="layui-btn layui-btn-danger layui-btn-sm ajax-delete"><i class="layui-icon">&#xe640;</i>删除模板</a>
        {/if}
    </script>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var dropdown = layui.dropdown;

        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableTrack',
            url: "{:url('wechat/template/index_json')}",
            page: true,
            limit:10,
            limits:[10,30,50,100,200,500,1000],
            loading:true,
            //totalRow: true,
            cols: [[
                {type: 'numbers', title: '序号'},
                {field: 'title', align: 'center', sort: true, title: '模板标题',width:220},
                {field: 'primary_industry', align: 'center', sort: true, title: '行业大类',width:220},
                {field: 'deputy_industry', align: 'center', sort: true, title: '行业小类',width:220},
                {field: 'example', align: 'left', title: '示例'},
                {templet: '#task', align: 'left', title: '待发送任务'},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', minWidth: 260}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                console.log(res)
                return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本
                  "count": res.data.total, //解析数据长度
                  "data": res.data.data //解析数据列表
                };
            }
        });
        
    });
</script>
{/block}